<!--
* Created by Sean on 2017/10/2.
* Feedback
-->
<template>
  <div id="feedback" class="feedback">
    <group>
      <x-textarea :max="800" name="feedback" :rows="10" placeholder="请输入意见反馈内容..." :show-counter="false" v-model="content"></x-textarea>
    </group>
    <div class="btn-wrapper"><x-button type="primary" @click.native="feedback">确定</x-button></div>
  </div>
</template>
<script>
  import { XTextarea } from 'vux'
  export default {
    name: 'feedback',
    components: {
      XTextarea
    },
    data () {
      return {
        content: '',
        userInfo: JSON.parse(localStorage.getItem('userInfo'))
      }
    },
    methods: {
      feedback () {
        if (this.content.trim() === '') {
          this.$vux.toast.text('内容不能为空', 'middle')
          return false
        }
        // let userId = localStorage.getItem('userInfo').userId
        // if (!userId) {
        //   this.$router.replace('/login')
        //   return false
        // }
        this.$axiosPosting(this.$api.feedback, {
          // userId,
          type: this.userInfo.userType,
          content: this.content.trim()
        }).then(json => {
          if (json.code === '0000') {
            this.$vux.toast.text(json.msg, 'middle')
            setTimeout(() => {
              this.$router.go(-1)
            }, 1200)
          } else {
            this.$vux.toast.text(json.msg, 'middle')
          }
        })
      }
    }
  }
</script>
<style lang="less">
  html {
    background: #FFFF;
  }
  .feedback {
    .weui-cells {
      margin-top: 0;
      padding: 1rem .75rem 0;
      .vux-x-textarea {
        padding: 0;
        border-bottom: 1px solid #D9D9D9;
        textarea {
          font-size: .65rem;
          color: #333;
          box-sizing: border-box;
        }
      }
    }
    .weui-cells:after {
      display: none;
    }
    .btn-wrapper {
      margin-top: 1rem;
      padding: 0 .75rem;
    }
  }
</style>
